import java.util.Arrays;
import java.util.Stack;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: LIUYANJIAO
 * Date: 2024-10-17
 * Time: 9:04
 */
public class Main {
    public static int evalRPN(String[] tokens){
        Stack<Integer> s=new Stack<>();
        for (int i = 0; i < tokens.length; i++) {
            if(tokens[i]!="+"&&tokens[i]!="-"&&tokens[i]!="*"&&tokens[i]!="/"){
                int a=Integer.parseInt(tokens[i]);
                s.push(a);
            }else if(tokens[i]=="+"){
                int c=s.pop();
                int b=s.pop();
                s.push(b+c);
            }else if(tokens[i]=="-"){
                int c=s.pop();
                int b=s.pop();
                s.push(b-c);
            }else if(tokens[i]=="*"){
                int c=s.pop();
                int b=s.pop();
                s.push(b*c);
            }else if(tokens[i]=="/"){
                int c=s.pop();
                int b=s.pop();
                s.push(b/c);
            }

        }
        return s.peek();
    }


    public static void main(String[] args) {
        String[] tokens={"2","1","+","3","*"};
        System.out.println(evalRPN(tokens));
    }
    public static boolean IsPopOrder(int[] pushV, int[] popV){
        Stack<Integer> s1=new Stack<>();
        Stack<Integer> s2=new Stack<>();
        for (int i = 0; i < popV.length; i++) {

                if(s1.empty()){
                    s1.push(popV[i]);
                }
                else if(popV[i]>s1.peek()){
                    s2.push(popV[i]);
                }else{
                    s1.push(popV[i]);
                }

        }
        for (int i = 0; i < pushV.length; i++) {
            if(!s1.empty()){
                if(pushV[i]!=s1.pop()){
                    return false;
                }
            } else if(!s2.empty()){
                if(pushV[i]!=s2.pop()){
                    return false;
                }
            }
        }
        return true;
    }
    public static void main1(String[] args) {
        int p1[]={1,2,3,4,5};
        int p2[]={4,3,5,1,2};
        System.out.println(IsPopOrder(p1,p2));

    }
}